<?php 
require_once '../include.php';
checkLogined();
$pageSize=10;
@$page=$_REQUEST['page']?(int)$_REQUEST['page']:1;

@$order=$_REQUEST['order']?$_REQUEST['order']:null;
@$keywords=$_REQUEST['keywords']?$_REQUEST['keywords']:null;

@$cateId = $_REQUEST['cateId']?$_REQUEST['cateId']:null;
@$proName = $_REQUEST['proName']?$_REQUEST['proName']:null;

@$whereStr = $_REQUEST['whereStr']?$_REQUEST['whereStr']:null;
if($cateId){
	$whereStr = "and c.id =".$cateId;
}
if($proName){
	$whereStr = "and p.pName like '%".$proName."%'";
}

$cateRows=getAllCate();  //项目类别列表
if(!$cateRows){
	alertMes("没有相应分类，请先添加分类!!", "addCate.php");
}

$rows=getProByPage($page,$pageSize,$whereStr);  //项目列表

?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>-.-</title>
<link rel="stylesheet" href="styles/backstage.css">
<link rel="stylesheet" href="scripts/jquery-ui/css/ui-lightness/jquery-ui-1.10.4.custom.css" />
<script src="scripts/jquery-ui/js/jquery-1.10.2.js"></script>
<script src="scripts/jquery-ui/js/jquery-ui-1.10.4.custom.js"></script>
<script src="scripts/jquery-ui/js/jquery-ui-1.10.4.custom.min.js"></script>
</head>

<body>
<div id="showDetail"  style="display:none;">

</div>
<div class="details">
                    <div class="details_operation clearfix">
                        <div class="bui_select">
                            <input type="button" value="添&nbsp;&nbsp;加" class="add" onclick="addPro()">
                        </div>
                        <div class="fr">
                            <div class="text">
                                <span>项目类别：</span>
                                <div class="bui_select">

                                    <select name="cId" id="" class="select" onchange="change(this.value)">
                                    	<option>-请选择-</option>
										<?php foreach($cateRows as $cateRow):?>
											<option value="<?php echo $cateRow['id'];?>"><?php echo $cateRow['cName'];?></option>
										<?php endforeach;?>
									</select>
                                </div>
                            </div>

                            <div class="text">
                                <span>项目名称搜索</span>
                                <input type="text" value="" class="search"  id="search" onkeypress="search()" >
                            </div>
                        </div>
                    </div>
                    <!--表格-->
                    <table class="table" cellspacing="0" cellpadding="0">
                        <thead>
                            <tr>
                                <th width="10%">编号</th>
                                <th width="10%">项目名称</th>
                                <th width="10%">项目分类</th>
                                <th width="10%">项目面积</th>
                                <th width="10%">项目介绍</th>
                                <th width="10%">委托单位</th>
                                <th width="10%">设计内容</th>
                                <th width="10%">设计时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php foreach($rows as $row):?>
                            <tr>
                                <!--这里的id和for里面的c1 需要循环出来-->
                                <td><label for="c1" class="label"><?php echo $row['pId'];?></label></td>
                                <td><?php echo $row['pName']; ?></td>
                                <td><?php echo $row['cName'];?></td>
                                <td><?php echo $row['pArea'];?></td>
                                 <td><?php echo $row['pDesc'];?></td>
                                  <td><?php echo $row['cUnit'];?></td>
                                  <td><?php echo $row['dDesc'];?></td>
                                  <td><?php echo $row['dTime'];?></td>
                                <td align="center">
                                				<input type="button" value="详情" class="btn" onclick="showDetail(<?php echo $row['pId'];?>,'<?php echo $row['pName'];?>')"><input type="button" value="修改" class="btn" onclick="editPro(<?php echo $row['pId'];?>)"><input type="button" value="删除" class="btn"onclick="delPro(<?php echo $row['pId'];?>)">
					                            <div id="showDetail<?php echo $row['pId'];?>" style="display:none;">
					                        	<table class="table" cellspacing="0" cellpadding="0">
					                        		<tr>
					                        			<td width="20%" align="right">项目名称</td>
					                        			<td><?php echo $row['pName'];?></td>
					                        		</tr>
					                        		<tr>
					                        			<td width="20%"  align="right">项目类别</td>
					                        			<td><?php echo $row['cName'];?></td>
					                        		</tr>
					                        		<tr>
					                        			<td width="20%"  align="right">项目面积</td>
					                        			<td><?php echo $row['pArea'];?></td>
					                        		</tr>
					                        		<tr>
					                        			<td width="20%"  align="right">项目介绍</td>
					                        			<td><?php echo $row['pDesc'];?></td>
					                        		</tr>
					                        		<tr>
					                        			<td  width="20%"  align="right">委托单位</td>
					                        			<td><?php echo $row['cUnit'];?></td>
					                        		</tr>
					                        		<tr>
					                        			<td  width="20%"  align="right">设计内容</td>
					                        			<td><?php echo $row['dDesc'];?></td>
					                        		</tr>
					                        		<tr>
					                        			<td  width="20%"  align="right">设计时间</td>
					                        			<td><?php echo $row['dTime'];?></td>
					                        		</tr>
					                        		<tr>
					                        			<td width="20%"  align="right">商品图片</td>
					                        			<td>
					                        			<?php 
					                        			$proImgs=getAllImgByProId($row['pId']);
					                        			foreach($proImgs as $img):
					                        			?>
					                        			<img width="100" height="100" src="uploads/<?php echo $img['albumPath'];?>" alt=""/> &nbsp;&nbsp;
					                        			<?php endforeach;?>
					                        			</td>
					                        		</tr>
					                        		
					                        	</table>
					                        	
					                        </div>
                                
                                </td>
                            </tr>
                           <?php  endforeach;?>
                           <?php if($totalRows>$pageSize):?>
                            <tr>
                            	<td colspan="9"><?php echo showPage($page, $totalPage,"whereStr={$whereStr}");?></td>
                            </tr>
                            <?php endif;?>
                        </tbody>
                    </table>
                </div>
<script type="text/javascript">
function showDetail(id,t){
	$("#showDetail"+id).dialog({
		  height:"auto",
	      width: "auto",
	      position: {my: "center", at: "center",  collision:"fit"},
	      modal:false,//是否模式对话框
	      draggable:true,//是否允许拖拽
	      resizable:true,//是否允许拖动
	      title:"商品名称："+t,//对话框标题
	      show:"slide",
	      hide:"explode"
	});
}
	function addPro(){
		window.location='addPro.php';
	}
	function editPro(id){
		window.location='editPro.php?id='+id;
	}
	function delPro(id){
		if(window.confirm("您确认要删除嘛？")){
			window.location="doAdminAction.php?act=delPro&id="+id;
		}
	}
	function search(){
		if(event.keyCode==13){
			var val=document.getElementById("search").value;
			window.location="listPro.php?proName="+val;
		}
	}
	function change(val){
		window.location="listPro.php?cateId="+val;
	}
</script>
</body>
</html>